package com.dingqb.more;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class BaseActivity extends Activity {

	BroadcastReceiver myRecerive = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			if(intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)){//电量变化
				//得到系统当前电量
                int level=intent.getIntExtra("level", 0);
                //取得系统总电量
                int total=intent.getIntExtra("scale", 100);
				Toast.makeText(BaseActivity.this, "电量变化", 0).show();
				
				
//				Intent.ACTION_SCREEN_ON;
//				Intent.ACTION_USER_PRESENT
				
				
			}else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)){//网络变化
				Toast.makeText(BaseActivity.this, "网络变化", 0).show();
				
			}

		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		IntentFilter filter=new IntentFilter();
		filter.addAction(Intent.ACTION_BATTERY_CHANGED);//电池
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);//网络
		registerReceiver(myRecerive, filter);
		
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
		if(myRecerive!=null){
			
			unregisterReceiver(myRecerive);
		}
	}

}
